﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitKernel.ElementCreatUtility.MultilineTextCreat;

namespace YJKRevitKernel.SampleAndTest.MultilineTextTest
{
	public partial class CreatMultilineTextForm : System.Windows.Forms.Form
	{
		public CreatMultilineTextForm(ExternalCommandData useData)
		{
			this.InitializeComponent();
			this.Data = useData;
		}

		public CreatMultilineTextForm(CreatMultilineTextForm inputOrigion)
		{
			this.InitializeComponent();
			this.Data = inputOrigion.Data;
			this.m_align = inputOrigion.m_align;
			this.m_multiFont = inputOrigion.m_multiFont;
			this.m_multiSize = inputOrigion.m_multiSize;
			this.m_rowPitch = inputOrigion.m_rowPitch;
			this.m_multiSize = inputOrigion.m_multiSize;
			this.MultiLocation = inputOrigion.m_multiLocation;
			this.lstText = inputOrigion.lstText;
			this.m_locationAlign = inputOrigion.m_locationAlign;
			this.cboxAlign.Text = inputOrigion.cboxAlign.Text;
			this.rtxtLstString.Text = inputOrigion.rtxtLstString.Text;
			this.CurrentObj();
		}

		public Dictionary<string, AlignType> Align
		{
			get
			{
				return this.m_align;
			}
			set
			{
				this.m_align = value;
			}
		}

		public ExternalCommandData Data
		{
			get
			{
				return this.m_data;
			}
			set
			{
				this.m_data = value;
			}
		}

		public double RowPitch
		{
			get
			{
				return this.m_rowPitch;
			}
			set
			{
				this.m_rowPitch = value;
			}
		}

		public List<string> LstText
		{
			get
			{
				return this.lstText;
			}
			set
			{
				this.lstText = value;
			}
		}

		public string MultiFont
		{
			get
			{
				return this.m_multiFont;
			}
			set
			{
				this.m_multiFont = value;
			}
		}

		public double MultiSize
		{
			get
			{
				return this.m_multiSize;
			}
			set
			{
				this.m_multiSize = value;
			}
		}

		public TextLocation MultiLocation
		{
			get
			{
				return this.m_multiLocation;
			}
			set
			{
				this.m_multiLocation = value;
				this.txtPositionX.Text = this.m_multiLocation.Position.X.ToString();
				this.txtPositionY.Text = this.m_multiLocation.Position.Y.ToString();
				this.txtPositionZ.Text = this.m_multiLocation.Position.Z.ToString();
			}
		}

		public AlignType LocationAlign
		{
			get
			{
				return this.m_locationAlign;
			}
			set
			{
				this.m_locationAlign = value;
			}
		}

		private void CreatMultilineTextForm_Load(object sender, EventArgs e)
		{
			string text = this.cboxAlign.Text;
			this.Align = new Dictionary<string, AlignType>();
			this.Align.Add("左上对齐", AlignType.LeftTop);
			this.Align.Add("左下对齐", AlignType.LeftBottom);
			this.Align.Add("右上对齐", AlignType.RightTop);
			this.Align.Add("右下对齐", AlignType.RightBottom);
			this.Align.Add("中心对齐", AlignType.Center);
			foreach (string item in this.Align.Keys)
			{
				this.cboxAlign.Items.Add(item);
			}
			this.txtPositionX.Enabled = false;
			this.txtPositionY.Enabled = false;
			this.txtPositionZ.Enabled = false;
			this.cboxAlign.SelectedIndex = 0;
			if (this.Align.Keys.Contains(text))
			{
				this.cboxAlign.Text = text;
			}
		}

		private void btnSelectPoint_Click_1(object sender, EventArgs e)
		{
			this.CurrentObj();
		}

		private void chkInputPoint_CheckedChanged(object sender, EventArgs e)
		{
			if (this.chkInputPoint.Checked)
			{
				this.txtPositionX.Enabled = true;
				this.txtPositionY.Enabled = true;
				this.txtPositionZ.Enabled = true;
				return;
			}
			this.txtPositionX.Enabled = false;
			this.txtPositionY.Enabled = false;
			this.txtPositionZ.Enabled = false;
		}

		private void btnOK_Click_1(object sender, EventArgs e)
		{
			if (this.CurrentObj() && this.MultiLocation.Position.IsAlmostEqualTo(XYZ.Zero))
			{
				try
				{
					XYZ position = new XYZ(double.Parse(this.txtPositionX.Text), double.Parse(this.txtPositionY.Text), double.Parse(this.txtPositionZ.Text));
					this.MultiLocation = new TextLocation(position, this.LocationAlign);
				}
				catch (Exception)
				{
					this.MultiLocation = new TextLocation(XYZ.Zero, this.LocationAlign);
				}
			}
			base.Close();
		}

		public bool CurrentObj()
		{
			bool result;
			try
			{
				this.txtRowPitch.Text = Math.Round(double.Parse(this.txtRowPitch.Text), 2).ToString();
				double rowPitch = double.Parse(this.txtRowPitch.Text);
				double multiSize = double.Parse(this.txtSize.Text);
				TextLocation multiLocation = null;
				try
				{
					multiLocation = new TextLocation(new XYZ(double.Parse(this.txtPositionX.Text), double.Parse(this.txtPositionY.Text), double.Parse(this.txtPositionZ.Text)), this.Align[this.cboxAlign.Text]);
				}
				catch (Exception)
				{
					multiLocation = new TextLocation(XYZ.Zero, this.Align[this.cboxAlign.Text]);
				}
				string[] array = this.rtxtLstString.Text.Split(new char[]
				{
					'\n'
				});
				List<string> list = new List<string>();
				for (int i = 0; i < array.Length; i++)
				{
					list.Add(array[i]);
				}
				this.LocationAlign = this.Align[this.cboxAlign.Text];
				this.MultiLocation = multiLocation;
				this.MultiFont = this.txtFont.Text;
				this.MultiSize = multiSize;
				this.LstText = list;
				this.RowPitch = rowPitch;
				result = true;
			}
			catch (Exception)
			{
				MessageBox.Show("请检查你的输入");
				result = false;
			}
			return result;
		}

		private void CreatMultilineTextForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			base.Close();
		}

		private void btnCancel_Click_1(object sender, EventArgs e)
		{
			base.Close();
		}

		private Dictionary<string, AlignType> m_align;

		private ExternalCommandData m_data;

		private string m_multiFont;

		private double m_multiSize;

		private double m_rowPitch;

		private TextLocation m_multiLocation;

		private List<string> lstText;

		private AlignType m_locationAlign;
	}
}
